<?php
	include("../connect/connect_dsccmis.php");
	$sql="call dscc.createTempOrphan;";
	$rs=mysql_query($sql);
	$sql = "call dscc.createTempEventCase;";
	$rs=mysql_query($sql);
	
	//แปลงประเภทเหตุการณ์จาก evntypid จาก evnrelevntyp ไปเป็น mis_evntypid โดยใช้ตาราง convert_evntype
	$sql = "drop table if exists mis_numvictim_losbodyWidow;";
	$rs=mysql_query($sql);
    $sql="create table mis_numvictim_losbodyWidow as 
	select t.whcdscc1,t.whevndte1,t.reg,left(t.plcidgen,2) as prov,right(left(t.plcidgen,4),2) as amp,t.perid
	from dscc.tempwidow t
	where (summlosbody<>'เสียชีวิต' or summlosbody is null)
	and sex='2'
	and whsummlosbody1='เสียชีวิต'
	and (left(whevnplcidgen1,2) in ('94','95','96') or left(whevnplcidgen1,4) in ('9003','9004','9005','9006'))
	and whperlostypid1 not in ('22','41')
	";
	
	$rs=mysql_query($sql);
	//mysql_free_result($rs);
	//mysql_close($c);
	if($rs){
	echo "<br>complete create mis_numvictim_losbodyWidow on dsccmis";
	}else{
		echo"can not process.";
	}
?>